﻿using LevelEditor.Document;
using LevelEditor.Forms;

namespace LevelEditor.View
{
    public class DoUndoRemoveTileSet : DoUndoNothing
    {
        #region Fields

        int LayerIndex;

        int Index;

        TileSet UndoTileSet;

        #endregion

        #region Constructors

        public DoUndoRemoveTileSet(MainForm form, int index):base(form)
        {
            LayerIndex = form.CurrentLayer;
            Index = index;
            UndoTileSet = form.Level.Layers[LayerIndex].TileSets[Index];
        }

        #endregion

        #region Methods

        public override bool Do()
        {
            MainForm.Level.Layers[LayerIndex].TileSets.RemoveAt(Index);
            MainForm.LayerViewControl.Views[LayerIndex].RebuildTileSetImages();
            MainForm.LayerViewControl.Views[LayerIndex].CheckTiles();
            MainForm.RefreshControlData();
            return base.Do();
        }

        public override void Undo()
        {
            MainForm.Level.Layers[LayerIndex].TileSets.Insert(Index, new TileSet(UndoTileSet));
            MainForm.LayerViewControl.Views[LayerIndex].RebuildTileSetImages();
            MainForm.CurrentLayer = LayerIndex;
            MainForm.RefreshControlData();
            MainForm.Palette.tabs.SelectedIndex = Index;
        }

        public override string ToString()
        {
            return "Remove tile set " + Index.ToString();
        }

        #endregion
    }
}
